﻿package mortal.game.view.godLuckGift.panel
{
    import com.gengine.core.frame.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.godLuckGift.data.*;
    import mortal.mvc.interfaces.*;

    public class GodLuckPassWin extends Window
    {
        protected var _bg:GImageBitmap;
        protected var _title:GImageBitmap;
        protected var _tip:GImageBitmap;
        protected var _centerBg:ScaleBitmap;
        protected var _godDes:GBitmap;
        protected var _coinDes:GBitmap;
        protected var _enterBtn:GLoadingButton;
        protected var _goldTxt:GTextFiled;
        protected var _coinTxt:GTextFiled;
        protected var _rwList:CellsGridSprite;
        protected var _pageSelector:PageSelecter;
        private var _pageTool:PageTool;
        private var _secTimer:SecTimer;
        private var _timeOutNum:int = 15;
        private var _giftLen:int = 5;
        private var _coin:int;
        private var _gold:int;
        private var _items:Array;
        private static var _instance:GodLuckPassWin;

        public function GodLuckPassWin(param1:ILayer = null)
        {
            super(param1);
            setSize(696, 357);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.godLuckGift, this.onResLoad);
            return;
        }// end function

        private function onResLoad() : void
        {
            this._bg = UIFactory.gImageBitmap(ImagesConst.GroupTowerFailTipBg, 0, -57, this);
            this._title = UIFactory.gImageBitmap(ImagesConst.GodLuckPassTitle, 211, -30, this);
            this._tip = UIFactory.gImageBitmap(ImagesConst.GodLuckPassTip, 176, 35, this);
            this._centerBg = UIFactory.bg(208, 87, 366, 148, this, ImagesConst.PanelBg);
            this._godDes = UIFactory.gBitmap(ImagesConst.GodLuckGold, 244, 99, this);
            this._coinDes = UIFactory.gBitmap(ImagesConst.GodLuckCoin, 397, 99, this);
            this._enterBtn = UIFactory.gLoadingButton(ImagesConst.ResultWindowBtn_upSkin, 329, 244, 114, 33, this);
            this._enterBtn.label = "";
            this._goldTxt = UIFactory.gTextField("12345645", 314, 98, 100, 25, this, GlobalStyle.textFormatHuang2.setSize(15).setBold(true));
            this._coinTxt = UIFactory.gTextField("12346798", 468, 98, 100, 25, this, GlobalStyle.textFormatHuang2.setSize(15).setBold(true));
            this._rwList = UIFactory.getUICompoment(CellsGridSprite);
            this._rwList.colNum = 5;
            this._rwList.vCellWid = 46;
            this._rwList.hCellWid = 100;
            this._rwList.genCellFun = this.genCells;
            this._rwList.genCells(5);
            this._rwList.x = 271;
            this._rwList.y = 147;
            this.addChild(this._rwList);
            this._pageSelector = UIFactory.pageSelecter(345, 201, this, PageSelecter.SingleMode);
            this._pageSelector.setbgStlye(ImagesConst.ComboBg, GlobalStyle.textFormatBai.center());
            this._pageSelector.maxPage = 1;
            this._pageSelector.pageTextBoxSize = 36;
            this._pageSelector.configEventListener(Event.CHANGE, this.onPageChange);
            this._giftLen = GodLuckGiftUtil.giftLen;
            this._pageTool = new PageTool([], this._giftLen);
            this._enterBtn.configEventListener(MouseEvent.CLICK, this.onCkHd);
            this._secTimer = new SecTimer(1);
            this._secTimer.addListener(TimerType.COMPLETE, this.onTimerCompleteHandler);
            this._secTimer.repeatCount = this._timeOutNum;
            this._secTimer.start();
            this.updateInfo(this._coin, this._gold, this._items);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            LoaderHelp.removeResEvent(ResFileConst.godLuckGift, this.onResLoad);
            this._bg = null;
            this._title = null;
            this._tip = null;
            this._centerBg = null;
            this._godDes = null;
            this._coinDes = null;
            this._enterBtn = null;
            this._goldTxt = null;
            this._coinTxt = null;
            this._rwList = null;
            this._pageSelector = null;
            this._pageTool = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            var _loc_2:* = this._pageTool.getByPageNo(this._pageSelector.currentPage);
            this._rwList.genCells(this._giftLen);
            this._rwList.updateAllNotDispose(_loc_2, null, "itemData", false);
            return;
        }// end function

        private function genCells() : BaseItem
        {
            var _loc_1:* = UIFactory.getUICompoment(BaseItem);
            _loc_1.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            _loc_1.isDragAble = false;
            _loc_1.isShowLock = true;
            return _loc_1;
        }// end function

        private function onCkHd(event:MouseEvent) : void
        {
            this.onTimerCompleteHandler(null);
            return;
        }// end function

        private function onTimerCompleteHandler(param1:SecTimer) : void
        {
            this._secTimer.stop();
            this.hide();
            return;
        }// end function

        public function updateInfo(param1:int, param2:int, param3:Array) : void
        {
            this._coin = param1;
            this._gold = param2;
            this._items = param3;
            if (this._coinTxt == null)
            {
                return;
            }
            this._coinTxt.text = "" + param1;
            this._goldTxt.text = "" + param2;
            if (param3)
            {
                this._pageTool.array = param3;
                this._pageSelector.maxPage = Math.ceil(param3.length / this._giftLen);
                this.onPageChange(null);
            }
            return;
        }// end function

        public static function get instance() : GodLuckPassWin
        {
            if (_instance == null)
            {
                _instance = new GodLuckPassWin;
            }
            return _instance;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
